package ferp.android.activities.preferences;

import android.content.Context;
import android.preference.EditTextPreference;
import android.util.AttributeSet;
import android.view.View;

/**
 * User: olegs
 * Date: 8/16/12 10:08 PM
 */
public class EditText extends EditTextPreference
{
  public static void setup(Preferences owner, int key, String value, String summary, int inputType, boolean enabled)
  {
    EditText preference = owner.find(EditText.class, key);

    preference.getEditText().setInputType(inputType);
    preference.update(value, summary);
    preference.setEnabled(enabled);
  }

  public EditText(Context context)
  {
    this(context, null);
  }

  public EditText(Context context, AttributeSet attrs)
  {
    super(context, attrs);
  }

  public void update(String value, String summary)
  {
    setText(value);
    setSummary(summary);
  }

  @Override
  protected void onBindView(View view)
  {
    super.onBindView(view);

    Preferences.initializePreferenceStyle(view, isEnabled());
  }

  @Override
  protected void onClick()
  {
    Preferences p = (Preferences)getContext();

    p.showDialog(Integer.valueOf(getKey()));
  }
}
